package com.xiaoyu.awakening.user.controller;

import com.xiaoyu.awakening.common.core.dto.Page;
import com.xiaoyu.awakening.common.core.dto.Result;
import com.xiaoyu.awakening.common.core.kit.ValidatorKit;
import com.xiaoyu.awakening.user.api.IUserControllerApi;
import com.xiaoyu.awakening.user.dto.UserBriefDto;
import com.xiaoyu.awakening.user.dto.UserDto;
import com.xiaoyu.awakening.user.dto.req.CreateUserReq;
import com.xiaoyu.awakening.user.dto.req.EditUserPersonalReq;
import com.xiaoyu.awakening.user.dto.req.SearchUserReq;
import com.xiaoyu.awakening.user.dto.req.UpdateUserReq;
import com.xiaoyu.awakening.user.dto.res.UpdateUserRes;
import com.xiaoyu.awakening.user.enums.UserErrorCodeEnums;
import com.xiaoyu.awakening.user.service.IUserService;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户管理API
 *
 * @author wangxiaoyu
 * @since v1.0
 */
@Log4j2
@RestController
@AllArgsConstructor
public class UserController implements IUserControllerApi {
    private final IUserService userService;

    @Override
    public Result<Void> create(@RequestBody @Valid CreateUserReq createUserReq) {
        String validMsg = ValidatorKit.validateEntityReturnMsg(createUserReq);
        if (StringUtils.isNotEmpty(validMsg)) {
            return Result.fail(UserErrorCodeEnums.USER_NAME_ERROR, UserErrorCodeEnums.USER_NAME_ERROR.getMessage() + ":" + validMsg);
        }
        userService.saveUser(createUserReq);
        return Result.success();
    }

    @Override
    public Result<String> delete(Long userId) {
        userService.logicDeleteUserById(userId);
        return Result.success("操作成功");
    }

    @Override
    public Result<UpdateUserRes> update(UpdateUserReq updateUserReq) {
        return null;
    }

    @Override
    public Result<String> edit(EditUserPersonalReq editUserPersonalReq) {
        return null;
    }

    @Override
    public Result<Page<UserDto>> search(SearchUserReq searchUserReq) {
        return null;
    }

    @Override
    public Result<UserBriefDto> info(Long userId) {
        return null;
    }

    @Override
    public Result<UserDto> details(Long userId) {
        return null;
    }
}
